/**
 * Created by wangshaohua on 2018/2/1.
 */
moduleLearningMap.controller("ConfigRouteForMap", function (LearningMapRouteResource, $scope, $log, $state, $stateParams, GeneralResource, LoadingService, ConstantService, DialogService) {
    initPage($scope);
    $scope.$on("ngDialog.opened", function () {
        dialogOnLoad();
    });

    // ------------------------------------------------------------------------------------------------------

    $scope.cancel = function () {
        DialogService.close();
    };

    $scope.queryRoute = function () {
        //LoadingService.show();
        var queryRoute = {
            className: Models.LearningMapRoute.className,
            query: {
                key: {
                    field: Models.LearningMapRoute.query.code,
                    matching: Matching.LIKE,
                    value: $scope.queryRouteKey
                }
            }
        };
        GeneralResource.queryPage({}, queryRoute, function (result) {
            $log.debug("查询结果", result.data);
            $scope.routeResults = result.data;
            //LoadingService.hide();
        });
    };

    $scope.setCurrentRoute = function (route) {
        $scope.currentConfig.name = route.name;
        $scope.currentConfig.code = route.code;
        $scope.currentConfig.id = route.id;
        $scope.currentConfig.routeId = route.id;
    };

    $scope.submit = function () {
        Alert.confirm(function () {
            //LoadingService.show();
            var bean = {
                learningMapId: $scope.currentConfig.learningMapId,
                routeId: $scope.currentConfig.id
            }
            LearningMapRouteResource.configRouteForLearningMap({}, bean, function (result) {
                $log.debug("查询结果", result.data);
                Alert.success();
                //LoadingService.hide();
                DialogService.close();
            });
        });
    };
});